package com.lwl.controller.scl;


import com.github.pagehelper.PageInfo;
import com.lwl.entity.LayData;
import com.lwl.entity.MyPage;
import com.lwl.entity.Tuser;
import com.lwl.entity.scl.TSclPlan;
import com.lwl.service.scl.TSclPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * (TSclPlan)表控制层
 *
 * @author makejava
 * @since 2022-10-29 18:46:15
 */
@Controller
@RequestMapping("tSclPlan")
public class TSclPlanController {
    /**
     * 服务对象
     */
    @Autowired
    private TSclPlanService tSclPlanService;

    /*
        查询所有计划
     */
    @GetMapping("queryAll")
    @ResponseBody
    public LayData queryAll(MyPage myPage, TSclPlan tSclPlan){
        PageInfo pageInfo = tSclPlanService.queryAll(myPage,tSclPlan);
        return new LayData(pageInfo);
    }

    /*
        检查邀请码
     */
    @PostMapping("checkCode")
    @ResponseBody
    public LayData checkCode(TSclPlan tSclPlan){
        Boolean i = tSclPlanService.checkCode(tSclPlan);
        return new LayData(i);
    }

    /*
        检查计划名字是否存在
     */
    @PostMapping("{planname}")
    @ResponseBody
    public LayData checkPlanname(@PathVariable String planname){
        Boolean i = tSclPlanService.checkPlanname(planname);
        return new LayData(i);
    }

    /*
        添加/修改计划
     */
    @PostMapping("addOrUpdataPlan")
    @ResponseBody
    public LayData addOrUpdataPlan(TSclPlan tSclPlan,HttpSession session){
        //System.out.println("====================================tSclPlan = " + tSclPlan);
        Tuser user = (Tuser) session.getAttribute("user");
        Boolean i = tSclPlanService.addOrUpdataPlan(tSclPlan,user);
        return new LayData(i);
    }

    /*
        删除计划
     */
    @DeleteMapping("delPlan/{id}/{code}")
    @ResponseBody
    public LayData delPlan(@PathVariable Integer id,@PathVariable String code){
        System.out.println("code ======================== " + code);
        System.out.println("id ========================= " + id);
        Boolean i = tSclPlanService.delPlan(id,code);
        return new LayData(i);
    }

    /*
        修改状态
     */
    @PostMapping("updUserStatus")
    @ResponseBody
    public LayData updUserStatus(TSclPlan tSclPlan){
        Boolean i = tSclPlanService.updUserStatus(tSclPlan);
        return new LayData(i);
    }

    /*
        通过验证码获取数据
     */
    @GetMapping("getByCode")
    @ResponseBody
    public LayData getByCode(TSclPlan tSclPlan){
        TSclPlan tSclPlan1 = tSclPlanService.getByCode(tSclPlan);
        return new LayData(tSclPlan1);
    }

    /*
        通过邀请码获取计划的id
     */
    @PostMapping("getPlanId/{yqcode}")
    @ResponseBody
    public LayData getPlanId(@PathVariable String yqcode){
        int planId = tSclPlanService.getPlanId(yqcode);
        return new LayData(planId);
    }
}
